[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2019-09-02
-->
[@JGP.head "表单编辑"/]
[@JGP.body]
    <jgp-div _row="['30','*']" _runit="px">
        <div slot="1-1">
            <jgp-btn  _fn="saveCallback"  _form="form">保存</jgp-btn>
        </div>
        <jgp-panel slot="2-1">
            <jgp-form _id="form" _action="/form/formApiController/saveFormAttr">
                <jgp-form-group _title="基本配置">
                    <jgp-text _label="LABEL" _name="label" _col="6"></jgp-text>
                    <jgp-text _label="NAME" _name="name" _col="6"></jgp-text>
                    <jgp-text _label="默认值" _name="value" _col="12"></jgp-text>
                    <jgp-num _label="行数" _name="row" _col="6" _value="1"></jgp-num>
                    <jgp-num _label="宽度" _name="col" _col="6" _value="6"></jgp-num>
                    <jgp-text _label="Label宽度" _name="labelWidth" _col="6" _value="80px"></jgp-text>
                    <jgp-radio _label="必填" _name="required" _col="6" _value="false"
                               _list="[{'label':'是','value':true},{'label':'否','value':false}]">
                    </jgp-radio>
                    <jgp-radio _label="查询参数" _name="forSearch" _col="6" _value="false"
                               _onchange="doForSearchChangeFn"
                               _list="[{'label':'是','value':true},{'label':'否','value':false}]">
                    </jgp-radio>
                    <jgp-radio _label="列表参数" _name="inGrid" _col="6" _value="true"
                               _list="[{'label':'是','value':true},{'label':'否','value':false}]">
                    </jgp-radio>
                    <jgp-drop _label="字段类型" _name="type" _col="6"
                              _value="TEXT"
                              _list="[{'label':'日期+时间','value':'DATE_TIME'},
                  {'label':'日期','value':'DATE'},
                  {'label':'时间','value':'TIME'},
                  {'label':'文本','value':'TEXT'},
                  {'label':'多行文本','value':'AREA'},
                  {'label':'数字','value':'NUMBER'},
                  {'label':'单选列表','value':'LIST_SINGLE'},
                  {'label':'多选列表','value':'LIST_MULTI'},
                  {'label':'单选下拉','value':'DROP_SINGLE'},
                  {'label':'多选下拉','value':'DROP_MULTI'},
                  {'label':'下拉树','value':'DROP_TREE'}]"
                              _onchange="doTypeChange"
                    ></jgp-drop>
                    <jgp-text  _is_show="false" _id="decimal-count" _name="decimal" _label="小数位" _value="0"></jgp-text>
                </jgp-form-group>
                <jgp-form-group _is_show="false" _id="query-config-group" _title="查询表单配置" _label_width="100px">
                    <jgp-num _label="列宽" _name="queryCol" _col="6" _value="6" ></jgp-num>
                    <jgp-drop _label="字段类型" _name="queryOperator" _col="6"
                              _value="eq"
                              _list="[{'label':'等于','value':'eq'},
                  {'label':'大于等于','value':'ge'},
                  {'label':'小于等于','value':'le'},
                  {'label':'大于','value':'gt'},
                  {'label':'小于','value':'lt'},
                  {'label':'%X%','value':'like'},
                  {'label':'%X','value':'likeL'},
                  {'label':'X%','value':'likeR'}]"></jgp-drop>
                </jgp-form-group>
                <jgp-form-group _id="list-config-group" _is_show="false" _title="列表配置">
                    <jgp-drop _label="下拉数据类型" _name="dropType" _col="12"
                              _value="ACTIVE_KEY"
                              _list="[{'label':'系统配置数据源','value':'ACTIVE_KEY'},
                  {'label':'REST 数据源','value':'REST'},
                  {'label':'本地数据源','value':'LOCAL'},
                  {'label':'微服务数据源','value':'MICRO'}]"
                              _onchange="changePage">
                    </jgp-drop>
                </jgp-form-group>
                <jgp-form-group _id="tree-config" _is_show="false" _title="树配置">
                    <jgp-text _label="下拉树URL" _name="tdataSource" _submit="false" _label_width="90px" _col="12" _onblur="buildDataSourceFn"></jgp-text>
                    <jgp-text _label="实体类型" _name="model" _col="8" _label_width="90px"></jgp-text>
                    <jgp-text _label="映射属性" _name="mapperName" _col="4"></jgp-text>
                </jgp-form-group>
                <jgp-slider _id="data-source-slider" _height="140px" _is_show="false" _class="inline-control" _list="['ACTIVE_KEY','REST','MICRO','LOCAL']" _page="ACTIVE_KEY">
                    <jgp-form-group slot="ACTIVE_KEY" _title="本地配置数据源">
                        <jgp-text _label="下拉标识" _name="ldataSource" _submit="false" _col="12" _onblur="buildDataSourceFn"></jgp-text>
                    </jgp-form-group>
                    <jgp-form-group slot="REST" _title="REST API 数据源">
                        <jgp-text _label="REST API" _name="rdataSource" _submit="false" _col="12" _onblur="buildDataSourceFn"></jgp-text>
                    </jgp-form-group>
                    <jgp-form-group slot="LOCAL" _title="本地数据源">
                        <jgp-text _label="本地数据源" _placeholder="a.b.XxxModel:显示属性" _name="localdataSource" _submit="false" _col="12"
                                  _onblur="buildDataSourceFn"></jgp-text>
                    </jgp-form-group>
                    <jgp-form-group slot="MICRO" _title="微服务数据源">
                        <jgp-text _label="服务名" _name="microAppName" _col="12" _submit="false" _onblur="buildDataSourceFn"></jgp-text>
                        <jgp-text _label="接口" _name="microApi" _col="12" _submit="false" _onblur="buildDataSourceFn"></jgp-text>
                    </jgp-form-group>
                </jgp-slider>
                <jgp-hidden _name="dataSource" _onchange="setDisplay"></jgp-hidden>
                <jgp-hidden _name="sort" _value="0"></jgp-hidden>
                <jgp-hidden _name="formId" _value="${formId!''}"></jgp-hidden>
            </jgp-form>
        </jgp-panel>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>

        JGP.$onload(function () {
            var attrId = '${attrId!''}';
            if(attrId){
                JGP.$post('/form/formApiController/queryFormAttrById/'+attrId,{},function (result) {
                    var fdata = result.data.fdata;
                    JGP.form('form').setFdata(fdata);
                })
            }
        })

        function setDisplay(args) {
            var form = JGP.form('form');
            var dataSource = args.back;
            var type = form.field('type');
            var dropType = form.field('dropType');
            if(type === 'DROP_TREE'){
                form.field('tdataSource',dataSource);
            }else if(dropType === 'ACTIVE_KEY'){
                form.field('ldataSource',dataSource);
            }else if(dropType === 'REST'){
                form.field('rdataSource',dataSource);
            }else if(dropType === 'LOCAL'){
                form.field('localdataSource',dataSource);
            }else if(dropType === 'MICRO'){
                var arr = dataSource.split(',');
                form.field('microAppName',arr[0]);
                form.field('microApi',arr[1]);
            }
        }

        function doTypeChange(args) {
            var type = args.back.value,
                decimalCount = JGP.text('decimal-count'),
                listConfigGroup = JGP.formGroup('list-config-group'),
                treeConfig = JGP.formGroup('tree-config'),
                dataSourceSlider = JGP.slider('data-source-slider');
            decimalCount.show(false);
            if(type ==='LIST_SINGLE'||type ==='LIST_MULTI'||type ==='DROP_SINGLE'||type ==='DROP_MULTI'){
                listConfigGroup.show(true);
                dataSourceSlider.show(true);
                treeConfig.show(false);
            }else if(type==='DROP_TREE'){
                listConfigGroup.show(false);
                dataSourceSlider.show(false);
                JGP.form('form').field('dropType','REST');
                treeConfig.show(true);
            }else if(type === 'NUMBER'){
                decimalCount.show(true);
                listConfigGroup.show(false);
                dataSourceSlider.show(false);
                treeConfig.show(false);
            }else {
                listConfigGroup.show(false);
                dataSourceSlider.show(false);
                treeConfig.show(false);
            }

        }

        function changePage(args) {
            JGP.slider('data-source-slider').goPage(args.back.value)
        }

        function saveCallback(result) {
            if(result.back.flag){
                JGP.$close(true);
            }
        }

        function buildDataSourceFn() {
            var form = JGP.form('form');
            var dropType = form.field('dropType');
            var type = form.field('type');
            if(type === 'DROP_TREE'){
                /*form.field('ldataSource',undefined);
                form.field('rdataSource',undefined);
                form.field('microAppName',undefined);
                form.field('microApi',undefined);*/

                var dataSource = form.field('tdataSource');
                form.field('dataSource',dataSource);
            }else if(dropType === 'ACTIVE_KEY'){
                /*form.field('rdataSource',undefined);
                form.field('tdataSource',undefined);
                form.field('microAppName',undefined);
                form.field('microApi',undefined);*/

                var dataSource = form.field('ldataSource');
                form.field('dataSource',dataSource);
            }else if(dropType === 'REST'){
                /*form.field('ldataSource',undefined);
                form.field('tdataSource',undefined);
                form.field('microAppName',undefined);
                form.field('microApi',undefined);*/

                var dataSource = form.field('rdataSource');
                form.field('dataSource',dataSource);
            }else if(dropType === 'LOCAL'){

                /*form.field('ldataSource',undefined);
                form.field('tdataSource',undefined);
                form.field('microAppName',undefined);
                form.field('microApi',undefined);*/

                var dataSource = form.field('localdataSource');
                form.field('dataSource',dataSource);
            }else if(dropType === 'MICRO'){
                var microAppName = form.field('microAppName');
                var microApi = form.field('microApi');
                var dataSource = microAppName+','+microApi;
                form.field('dataSource',dataSource);
            }
        }

        function doForSearchChangeFn(args) {
            var group = JGP.formGroup('query-config-group');
            group.show(!!args.back);
        }
    </script>
[/@JGP.foot]